package net.zjitc.jdbc;



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @Author admin
 * @Date 2019/4/24 11:17
 */
public class PreparedStatementTest3 {
    public static void main(String[] args) {
        Connection conn=null;
        PreparedStatement pstmt=null;
        ResultSet rs=null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url="jdbc:mysql://localhost:3306/hxy";
            String user="root";
            String password="123456";
            conn= DriverManager.getConnection(url,user,password);
            String sql="select * from user";
            pstmt=conn.prepareStatement(sql);
            rs=pstmt.executeQuery();
            System.out.println("id\tname\tage");
           while (rs.next()){
               int id=rs.getInt("id");
               String name=rs.getString("name");
               String age=rs.getString("age");
               System.out.println(id+"\t"+name+"\t"+age);
           }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
